<?php
class FloatDataHandle extends AbsDataHandle {
	private static $options = array(
		'value' => null,
		'precision' => 2,
		'max' => PHP_INT_MAX,
		'min' => 0,
	);
	
	public static function getType() {
		return 'float';
	}
	
	public static function handle($defineCfg) {
		$options = (isset($defineCfg['options']) && is_array($defineCfg['options'])) ? $defineCfg['options'] : array();
		
		$options = array_merge(self::$options, $options);
		
		return self::genData($options);
	}
	
	private static function genData($options) {
		if(null !== $options['value']) $data = $options['value'];
		else {
			$data = mt_rand($options['min'], $options['max'] - 1);
			$base = pow(10, $options['precision']);
			$digit = mt_rand(0, $base - 1) / $base;
			
			$data += $digit;
		}
		
		return (float)$data;
	}
}
?>